/*
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements.  See the NOTICE file distributed with
 *   this work for additional information regarding copyright ownership.
 *   The ASF licenses this file to You under the Apache License, Version 2.0
 *   (the "License"); you may not use this file except in compliance with
 *   the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.crois.barrier.common.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;

/***
 * PluginEnum.
 */
@RequiredArgsConstructor
@Getter
public enum PluginEnum {

    /**
     * Global plugin enum.
     */
    GLOBAL(0, 0, "global"),
    /**
     * ip_black_white.
     */
    IP_BLACK_WHITE(1, 0, "ip_black_white"),
    /**
     * auth plugin enum.
     */
    AUTH(2, 0, "auth"),
    /**
     * param_mapping enum.
     */
    PARAM_MAPPING(3, 0, "param_mapping"),
    /**
     * request enum.
     */
    REQUEST(4, 0, "request"),
    /**
     * gray plugin enum.
     */
    GRAY(7, 0, "gray"),
    /**
     * Waf plugin enum.
     */
    WAF(10, 0, "waf"),

    /**
     * Rate limiter plugin enum.
     */
    RATE_LIMITER(20, 0, "rate_limiter"),

    /**
     * Rewrite plugin enum.
     */
    REWRITE(30, 0, "rewrite"),

    /**
     * Redirect plugin enum.
     */
    REDIRECT(40, 0, "redirect"),


    /**
     * Hystrix plugin enum.
     */
    HYSTRIX(45, 0, "hystrix"),
    /**
     * gray_ plugin enum.
     */
    ROUTE_GRAY_LOADBALANCER_CLIENT(46, 0, "route_gray_loadbalancer_client"),
    /**
     * Divide plugin enum.
     */
    ROUTE_TO_REQUEST_URL(47, 0, "route_to_request_url"),
    /**
     * Divide plugin enum.
     */
    ROUTE_LOADBALANCER_CLIENT(48, 0, "route_loadbalancer_client"),
    /**
     * netty_route plugin enum.
     */
    NETTY_ROUTE(52, 0, "netty_route"),
    /**
     * Divide plugin enum.
     */
    WEB_CLIENT_ROUTE(52, 0, "web_client_route"),

    /**
     * webSocket plugin enum.
     */
    WEB_SOCKET(52, 0, "webSocket"),
    /**
     * Retry plugin enum.
     */
    RETRY(53, 0, "retry"),
    /**
     * cache plugin enum.
     */
    CACHE(60, 0, "cache"),
    /**
     * Log plugin enum.
     */
    LOG(61, 0, "log"),
    /**
     * Monitor plugin enum.
     */
    MONITOR(80, 0, "monitor"),

    /**
     * Statics plugin enum.
     */
    STATICS(90, 0, "statics"),
    /**
     * nettyClient http Response plugin enum.
     */
    NETTY_CLIENT_RESPONSE(100, 0, "netty_client_response"),
    /**
     * webClient http Response plugin enum.
     */
    WEB_CLIENT_RESPONSE(100, 0, "webclient_response");

    private final int code;

    private final int role;

    private final String name;

    /**
     * get plugin enum by name.
     *
     * @param name plugin name.
     * @return plugin enum.
     */
    public static PluginEnum getPluginEnumByName(final String name) {
        return Arrays.stream(PluginEnum.values())
                .filter(pluginEnum -> pluginEnum.getName().equals(name))
                .findFirst().orElse(PluginEnum.GLOBAL);
    }
}
